/*
 * FileAsMsg plug-in for Miranda IM and QIP Infium.
 * Sending/receiving files via instant messaging without protocol support.
 * Homepage: http://code.google.com/p/fileasmsg/
 *
 * Copyright (c) 2008, Radist <radist.nt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Name(s) of contributor(s) may not be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Radist ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Radist BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FILEASMESSAGE_CODER__H__R___
#define __FILEASMESSAGE_CODER__H__R___

#include <Windows.h>

class TransferFile;

class CoderIf
{
	TransferFile *file;
	DWORD next_chunk;
	bool do_rehash;
	const char *fhash;
	char *desiredhash;
	CoderIf(){};
protected:
	DWORD flags;
	CoderIf(TransferFile*_f, DWORD _flags);
	virtual const char *HashPiece(const unsigned char*, size_t)=0;//return the link to field with hash string
	virtual void ResetHashing(void)=0;//reinitialize file hashing procedure
	virtual const char *FinishHash(void)=0;//return the link to field with file hash
	virtual bool EncodeData(char*, size_t, const unsigned char*, size_t)=0;//return false if string peace to small
	virtual size_t DecodeData(unsigned char*, size_t, const char*)=0;//return actual decoded piece size or 0 if error
public:
	virtual ~CoderIf()=0;//just destructor
	void NotifyHash(const char*_hash);
	bool HashNitified(void);
	bool CheckHash(void);
	const char* GetHash(void);
	virtual void AddHashPart(const unsigned char*, size_t)=0;//include given file part to hash
	size_t Encode(char*msg, size_t msgsize, const unsigned char*data, size_t datasize);
	bool Decode(unsigned char*data, size_t datasize, const char*msg, DWORD chunk_no);
	static CoderIf *CreateCoderIf(TransferFile*file, DWORD flags);//factory method
};

#endif//__FILEASMESSAGE_CODER__H__R___